package it.antonio.ilpizze.te;

public abstract class Token {
	
	public static final char OPEN = '{'; 
	public static final char CLOSE = '}'; 
	public static final char VALUE = '$'; 
	public static final char OPERATION = '#'; 
	public static final char INVERTED_OPERATION = '^'; 
	public static final char END_OPERATION = '/'; 
	public static final char POINT = '.'; 
	public static final char TWO_POINTS= ':';
	public static final char ESCAPE = '\\'; 
	public static final char FILTER = '>'; 
	
	public int position;
	public Token next;
	
	public Token(int position) {
		this.position = position;
	}
	
	public abstract boolean isSpecial(char c);
	public abstract boolean isText();
	public abstract String asText();
	
	public boolean hasNext(){
		return next != null;
	}
	
	@Override
	public String toString() {
		return "TOKEN[\"" + asText() + "\"]";
	}
	
	public static Token special(int position, final char token){
		return new Token(position) {
			
			@Override
			public boolean isText() {
				return false;
			}
			
			@Override
			public boolean isSpecial(char c) {
				return c == token;
			}
			
			@Override
			public String asText() {
				return Character.toString(token);
			}
		};
	}
	
	public static Token text(int position, final String token){
		return new Token(position) {
			
			@Override
			public boolean isText() {
				return true;
			}
			
			@Override
			public boolean isSpecial(char c) {
				return false;
			}
			
			@Override
			public String asText() {
				return token;
			}
		};
	}
	
}
